<template>
  <div class="student-manage-container">
    <el-card shadow="hover">
      <div class="header">
        <h2>学生管理</h2>
        <el-input v-model="search" placeholder="搜索姓名/学号" class="search-input" clearable />
        <el-button type="primary" @click="onAdd" icon="el-icon-plus">添加学生</el-button>
      </div>
      <el-table :data="students" stripe border style="width: 100%; margin-top: 20px;">
        <el-table-column prop="username" label="学号" width="120" />
        <el-table-column prop="real_name" label="姓名" width="120" />
        <el-table-column prop="gender" label="性别" width="80" />
        <el-table-column prop="phone" label="手机号" width="120" />
        <el-table-column prop="id_card" label="身份证" width="160" />
        <el-table-column prop="college" label="学院" width="120" />
        <el-table-column prop="grade" label="年级" width="80" />
        <el-table-column prop="clazz" label="班级" width="80" />
        <el-table-column label="操作" width="180">
          <template #default="scope">
            <el-button size="small" @click="onEdit(scope.row)" icon="el-icon-edit">编辑</el-button>
            <el-button size="small" type="danger" @click="onDelete(scope.row)" icon="el-icon-delete">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog v-model="dialogVisible" title="学生信息" width="400px">
      <el-form :model="form">
        <el-form-item label="学号"><el-input v-model="form.username" /></el-form-item>
        <el-form-item label="姓名"><el-input v-model="form.real_name" /></el-form-item>
        <el-form-item label="性别"><el-select v-model="form.gender"><el-option label="男" value="男" /><el-option label="女" value="女" /></el-select></el-form-item>
        <el-form-item label="手机号"><el-input v-model="form.phone" /></el-form-item>
        <el-form-item label="身份证"><el-input v-model="form.id_card" /></el-form-item>
        <el-form-item label="学院"><el-input v-model="form.college" /></el-form-item>
        <el-form-item label="年级"><el-input v-model="form.grade" /></el-form-item>
        <el-form-item label="班级"><el-input v-model="form.clazz" /></el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="dialogVisible=false">取消</el-button>
        <el-button type="primary" @click="onSave">保存</el-button>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import { ref } from 'vue';
const search = ref('');
const students = ref([
  { username: '2021001', real_name: '学生1', gender: '男', phone: '13800000001', id_card: '440000000000000001', college: '计算机学院', grade: '2021', clazz: '1班' },
  { username: '2021002', real_name: '学生2', gender: '女', phone: '13800000002', id_card: '440000000000000002', college: '管理学院', grade: '2022', clazz: '2班' },
]);
const dialogVisible = ref(false);
const form = ref({});
function onAdd() { form.value = {}; dialogVisible.value = true; }
function onEdit(row) { form.value = { ...row }; dialogVisible.value = true; }
function onDelete(row) { students.value = students.value.filter(s => s.username !== row.username); }
function onSave() { dialogVisible.value = false; }
</script>
<style scoped>
.student-manage-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 0;
  background: #f5f7fa;
  min-height: 100vh;
}
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
}
.search-input {
  width: 220px;
}
</style> 